var userId = getCookie("uid");
if (userId != null) {
    window.location.href = "homePage.html";
}
$(function() {
    $("#error").hide();
    $("#login").click(function() {
        var username = $("#username").val().trim();
        var password = $("#password").val().trim();
        $.ajax({
            url : "/SofaGuest/login/login.do",
            type : "post",
            data : {
                "userName" : username,
                "passWord" : password
            },
            datatype : "json",
            success : function(result) {
                if (result.status == '0000') {
                    addCookie("uid", username, 2);
                    addCookie("userType", result.data.user_type, 2);
                    addCookie("realName", result.data.real_name, 2);
                    window.location.href = "homePage.html";
                }
                else {
                    alert(result.detial);
                    $("#errorMsg").html(result.detial);
                    $("#error").show();
                }
            },
            error : function() {
                alert("系统异常,请稍后重试");
            }
        });
    });
});
